﻿create PROCEDURE Sync.SP_CustomerPhones_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[PhoneID],
		g.[CustomerID],g.[PhoneType],g.[PhoneNumber],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[CustomerPhones] g RIGHT JOIN Sync.CustomerPhones_Tracking t  
    ON t.PhoneID = g.PhoneID 
    join [CustomerLoans] cl
		on (g.CustomerID = cl.CustomerID or g.CustomerID = cl.GuarantorID)
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
	AND ((@FilterdColumn IS NULL) OR (cl.CommitteeID = @FilterdColumn))
    END














